const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    newPir: 0,
    newPirce: 0,
    // 需要滚动的时间
    duration: 2000,
    // 初始值
    startVal: 0,
    // 最终值
    endVal: 2018,
    value: '',
    todayVisit: 0,
    monthVisit: 0,
    todaySum: 0,
    monthSum: 0,
    todaySold: 0,
    monthSold: 0,

    outStocks: [],
    taskTotal: 0.0,
    topUsers_id: [],
    orderNums: 0,

    monthTotalSales: 0,
    monthVisitNum: 0,
    todayTotalSales: 0,
    todayVisitNum: 0,

    tops: [],
    visitList: [],
  },


  toPage(e) {
    var flag = e.currentTarget.dataset.flag

    if (flag == 'out_stock') {
      wx.navigateTo({
        url: '/productPackage/pages/outStock/outStock',
      })
    } else if (flag == 'statistics') {
      // 销售统计
      wx.navigateTo({
        url: '/recordPackage/pages/saleRecord/saleRecord',
      })
    } else if (flag == 'customer') {
      wx.switchTab({
        url: '/pages/customer/customer',
      })

    } else if (flag == 'visit') {
      wx.navigateTo({
        url: '/recordPackage/pages/visitRecord/visitRecord',
      })
    } else if (flag == 'bust') {

    } else if (flag == '0') {
      // 更多销量排名
    } else if (flag == '1') {
      // 更多拜访排名
    }

  },
  // 搜索 
  toSearch() {},

  toMySelf() {},
  infoHref() {},


  getUserData() {
    var url = app.globalData.url + "user/getUserInfo",
      that = this,
      monthTotalSales = 0,
      monthVisitNum = 0,
      todayTotalSales = 0,
      todayVisitNum = 0;
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {
        userId: app.globalData.userId,
      }, res => {
        console.log(res);
        if (res.flag) {
          var res = res.data
          wx.hideLoading()

          that.setData({
            monthTotalSales: res.monthTotalSales,
            monthVisitNum: res.monthVisitNum,
            todayTotalSales: res.todayTotalSales,
            todayVisitNum: res.todayVisitNum,
          })

          console.log(res);
        }
      },
      err => {
        console.log(err);
      })
  },
  getUserSaleRanking() {
    var url = app.globalData.url + "user/getUserSaleRanking",
      that = this,
      tops = [],
      visitList = [];
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {
        companyId: app.globalData.companyId
      }, res => {
        console.log(res);
        if (res.flag) {
          var res = res.data
          wx.hideLoading()
          that.setData({
            tops: res.saleList,
            visitList: res.visitList,
          })
          wx.stopPullDownRefresh()
          console.log(res);
        }
      },
      err => {
        console.log(err);
      })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getUserData()
    this.getUserSaleRanking()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getUserData()
    this.getUserSaleRanking()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})